﻿@model Model.SysUserInfo
@using WebPortal.MvcExtension
@{
    ViewBag.Title = "编辑用户信息";
    Layout = "~/Views/Shared/_Main.cshtml";
}
@section Head{
    <script src="/Scripts/FormCheck.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            if ('@Model.Guid' == "") {
                $(".trEmployeeCode").hide();
            }
            page_Init();
            //InitList();
        });
        function page_Init() {
            $("body").css("overflow", "hidden");
        }
        function btnSave_Click() {
            submitForm();
        }

        function btnBack_Click() {
            window.location = "/SysUser/UserList";
        }
        //----------提交数据 ----------------
        function submitForm() {
            var pwd = $.trim($("#Pwd").val());
            if ($.trim($("#EmployeeName").val()) == "") {
                alert("姓名不能为空！");
                return false;
            }
            if ($.trim($("#Username").val()) == "") {
                alert("用户名不能为空！");
                return false;
            }
            if (pwd == "") {
                alert("密码不能为空！");
                return false;
            }
            if (pwd != $("#OldPwd").val()) {
                if (!checkPwdNum(pwd)) {
                    alert("密码格式不正确，密码长度至少8位，必须包含数字、字母、特殊字符。");
                    return false;
                } 
            }
            var result = $("#Username").val().match(/^\w+$/);
            if (result == null) {
                alert("用户名格式不正确，只能由数字、英文字母或者下划线组成!");
                return false;
            }
            if (pwd != $.trim($("#QRPwd").val())) {
                alert("两次输入密码不一致，请重新输入！");
                return false;
            }
            if ($.trim($("#Mobile").val()) != "" && !CheckMobile($.trim($("#Mobile").val()))) {
                alert("手机号码格式不正确，请重新输入！");
                return false;
            }
            if ($.trim($("#OfficeEmail").val()) != "" && !CheckEmail($.trim($("#OfficeEmail").val()))) {
                alert("Email格式不正确，请重新输入！");
                return false;
            }

            if ($('#ff').form("validate")) {
                var postUrl = "/SysUser/UpDate";
                var postData = $(":input").serialize();
                $.ajax({
                    type: "POST",
                    async: true,
                    url: postUrl,
                    data: postData,
                    success: function (result) {
                        if (result == 1) {
                            alert("操作成功！");
                            btnBack_Click();
                        } else if (result == 2) {
                            alert("操作失败！存在相同用户名。");
                        }
                        else {
                            alert(result);
                        }
                    }
                });
            }
        }
        //----------提交数据 END----------------
    </script>
}
<div style="margin: 5px;">
    @{
        // 渲染输出列表
        var dataToolbar = new ViewDataDictionary();
        dataToolbar.Add("PanelTitle", "编辑用户");
        dataToolbar.Add("ShowSaveButton", true);
        dataToolbar.Add("ShowBackButton", true); 
        @Html.Partial("_ToolBarPanel", dataToolbar);
    }
    @using (Html.BeginForm("UpDate", "SysUser", FormMethod.Post, new { id = "ff" }))
    {
       
        @Html.Partial("_EditUser", Model)
    }
</div>
